import Taro, { Component } from '@tarojs/taro'
import { View, Text, Image,Button} from '@tarojs/components'
import { observer, inject } from '@tarojs/mobx'
import './user-page.scss'

@inject('Store')
@observer
class UserPage extends Component {
  constructor(props) {
    super(props)

  }
  componentWillMount() {}
  componentDidMount() {

  }
  render() {
    let show=this.props.Store.show;                     //先取值，不然render函数虽然触发但是不会更新ui
    let userAvatar=this.props.Store.userInfo.avatarUrl;
    let nickName = this.props.Store.userInfo.nickName
    return (
      <View className='user-wrap'>
        <View className='user-info'>
          <Image
            className='user-avatar'
            src={userAvatar}
          />
          <Text className='user-name'>{nickName}</Text>
          {show? 
          <Button open-type='getUserInfo'
            onGetUserInfo={(e)=>{
              let self=this
              if(e.detail.userInfo){
                console.log('successful')//授权成功点击了确认按钮，小程序原版为bindgetuserinfo="bindGetUserInfo"
                self.props.Store.hiddenButton()
                self.props.Store.updateUserInfo(userRes.userInfo)
              }else{
                console.log('fail');//授权失败
              }
            }}
          >授权登录</Button>
          :''}
        </View>
      </View>
    )
  }
}

export default UserPage
